<%--
 *  File:    DataCleanPeriodDetailInfo.jsp
 *  @Author: Jamesli
 *  Date:    2010/06/21
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>
<%@ page import="java.text.DateFormat,java.text.SimpleDateFormat"%>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DataCleanPeriodDetailInfo"); 
%>

<%
  //init param
  String strModuleName = "CM";
  String privilegeCode = "E0131";
  String contextPath = request.getContextPath();
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>DataCleanPeriodDetailInfo</title>
<PageFlow:CheckPageFlow pageName="p_datacleanperioddetail"/>
<% 
  	String iscontinuum = (String)pageContext.getAttribute("iscontinuum");
  	
  	 Integer periodstatus = (Integer)pageContext.getAttribute("periodstatus");
  	 if(periodstatus == null){
  	 	periodstatus = new Integer(-1);
  	 }
  	 
%>
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<script>
function page_monthas(){
	var id = document.cform.periodid.value;
	if(id == null || id.length == 0 || id == "" || id == "-1") return;
	if (!confirm('<%= message.getMessageDesc("ARE_YOU_SURE")%>')) return;
	cform.target = "_self";
	document.cform.actionname.value = "monthas";
	isRunning = true;
	document.cform.submit();  
}
</script>
</head>

<body>

<table width="100%" cellspacing="0" border="0" cellpadding="0">
 <form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_parent">
    <input type="hidden" name="pagename" value="p_datacleanperiodsummary">
    <input type="hidden" name="actionname">
    <custom:hidden property="periodid"/>
    <custom:hidden property="reloadflag"/>
  <tr> 
    <td> 
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
            <td class="title_center"><%= label.getLabelName("L_SerialNo") %></td>
            <td width="25%" class="title_center"><%= label.getLabelName("L_PeriodStartDate") %></td>
            <td width="25%" class="title_center"><%= label.getLabelName("L_PeriodEndDate") %></td>
            <td width="20%" class="title_center"><%= label.getLabelName("L_UseStatus") %></td>
         </tr>
         <%
             int j = 0;
             String strClassType = new String(); 
             Integer nDefaultDetailId = new Integer(-1);    
             boolean bHasChecked = false;
             Vector details = (Vector)pageContext.getAttribute("details");
             if(details == null) details = new Vector();
               
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
			Date lastEndDate = new Date();
			Date newStartDate = new Date();
			String newstartdate = "";
			boolean newstartdatereadonly = false;
			
			if("Y".equalsIgnoreCase(iscontinuum)){
			    if( details.size() == 0 ){
			    	lastEndDate = new Date();	
			    }else{
			    	HashMap lastHash = (HashMap)details.get(details.size()-1);
				    		   
				    if( lastHash == null ){
				        lastHash = new HashMap();
				    }
				    if( lastHash.get("enddate") != null ){
				        lastEndDate = (Date)lastHash.get("enddate");
				    }
				
				    Calendar c1 = Calendar.getInstance();
				    c1.setTime(lastEndDate);
				    c1.add(Calendar.DATE, 1);
				    newStartDate = c1.getTime();  
				    newstartdatereadonly = true;
			    }
			    newstartdate = df.format(newStartDate);
			}
          %>
          <logic:iterate id="detail" collection="<%= details %>">                      
         <%
            HashMap detailMap = (HashMap)pageContext.getAttribute("detail");
            if(detailMap == null) detailMap = new HashMap();
            String strIsChecked = new String("");
            
            if(j%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
            
           	if(!bHasChecked)
            {
              strIsChecked = "Checked";                       
              bHasChecked = true;
              nDefaultDetailId = (Integer)detailMap.get("dcperioddetailid");      
            }
            j++;     
          %>
           <tr class="<%=JspHelper.filterNull(strClassType)%>">
            <td>&nbsp;<custom:write property="periodno" name="detail"/></td>
            <td>&nbsp;<custom:write property="startdate" name="detail"/></td>
            <td>&nbsp;<custom:write property="enddate" name="detail"/></td>
            <td class="td_center"><custom:write property="status" name="detail" dictType="Status" nbsp="true"/></td>
          </tr>
          </logic:iterate>
          <%//---------------set default value-------------------- %>
          <input type="hidden" name="detailid" value="<%=JspHelper.filterNull( nDefaultDetailId )%>">
          <input type="hidden" name="numrows" value="<%=JspHelper.filterNull( j )%>">
          <input type="hidden" name="currentrow" value="1">        
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr> 
          <td class="td_center">
            <a onclick="page_monthas()"><custom:button type="1" label="L_MonthAS" imgsrc="CreatSubDept.gif" border="0" style="width:60"/></a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
 </form>
</table>
</body>
</html>
<script language="javascript">
	if(document.cform.reloadflag.value == 'Y')
	{
		document.cform.reloadflag.value="";
		var strLocation = parent.up.location.href;
		
		var id = document.cform.periodid.value;
		//alert(strLocation);
		parent.up.location.href="DataCleanPeriodSummary.jsp?<%= OvalTools.randomURL() %>&periodid=" + id;
		//parent.up.location.reload();
	}
</script>


